package com.robot.mvvm.ui.work

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.robot.base.base.activity.GLBaseFragment
import com.robot.base.configs.AppConstants
import com.robot.base.model.QuestionDetailDTOBean
import com.robot.base.model.QuestionLogDTOBean
import com.robot.mvvm.BR
import com.robot.mvvm.R
import com.robot.mvvm.databinding.AppFragmentRepairWorkOrderDetailScheduleBinding
import com.robot.mvvm.ui.work.adapter.RepairWorkOrderScheduleAdapter
import com.robot.mvvm.vm.work.RepairWorkOrderScheduleViewModel

class RepairWorkOrderScheduleFragment :
    GLBaseFragment<AppFragmentRepairWorkOrderDetailScheduleBinding, RepairWorkOrderScheduleViewModel>() {

    var mRepairWorkOrderScheduleAdapter: RepairWorkOrderScheduleAdapter? = null
    var questionId: String = ""
    companion object {
        fun newInstance(questionId: String): RepairWorkOrderScheduleFragment {
            val fragment = RepairWorkOrderScheduleFragment()
            val bundle = Bundle()
            bundle.putString(AppConstants.BundleKey.QUESTION_ID, questionId)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initParam() {
        super.initParam()
        questionId = arguments?.getString(AppConstants.BundleKey.QUESTION_ID) ?: ""
    }

    override fun initContentView(
        inflater: LayoutInflater?,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): Int = R.layout.app_fragment_repair_work_order_detail_schedule

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        initAdapter()
        viewModel.getLogListByQuestionId(questionId)

    }

    fun initAdapter(){
        mRepairWorkOrderScheduleAdapter = RepairWorkOrderScheduleAdapter()
        binding.mRv.apply {
            layoutManager = LinearLayoutManager(requireContext())
            adapter = mRepairWorkOrderScheduleAdapter
        }
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uc.refreshDataEvent.observe(this){
            mRepairWorkOrderScheduleAdapter?.setNewInstance(it as MutableList<QuestionLogDTOBean>?)
        }
    }
}